package com.aix.demo.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.aix.demo.api.os.EnvironmentActivity;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class MainActivity extends ListActivity {
	
	private ArrayList<Map<String, Object>> list = new ArrayList<Map<String,Object>>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		addItem("custom layout", CustomLayoutActivity.class);
		addItem("no view group activity", NoViewGroupActivity.class);
		addItem("frame layout", FrameLayoutActivity.class);
		addItem("linear layout", LinearLayoutActivity.class);
		addItem("shape activity", ShapeActivity.class);
		addItem("popup window", PopupWindowActivity.class);
		addItem("layout animation", LayoutAnimationsActivity.class);
		addItem("gridlayout", GridLayoutActivity.class);
		addItem("calculator", CalculatorActivity.class);
		addItem("horizontal scroll view", HorizontalScrollViewActivity.class);
		addItem("async tasks", AsyncTaskActivity.class);
		addItem("notification demo", NotificationActivity.class);
		addItem("timer task without service", TimerTaskWithoutServiceActivity.class);
		addItem("view group event dispatch", ViewGroupEventActivity.class);
		addItem("shared preferences", SharedPreferencesActivity.class);
		addItem("create file", SDCardActivity.class);
		addItem("os environment", EnvironmentActivity.class);
		addItem("spinner", SpinnerActivity.class);
		addItem("switch", SwitchActivity.class);
		addItem("ListView", ListViewActivity.class);
		addItem("view api", ViewActivity.class);
		addItem("drag drop scroll view activity", DragDropScrollViewActivity.class);
		addItem("sqlite activity", SQLiteActivity.class);
		
        setListAdapter(new SimpleAdapter(this, list,
                android.R.layout.simple_list_item_1, new String[] { "title" },
                new int[] { android.R.id.text1 }));
        getListView().setTextFilterEnabled(true);
	}
	
	public void addItem(String title, Class<?> cls) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("title", title);
		Intent intent = new Intent();
		intent.setClass(this, cls);
		map.put("intent", intent);
		list.add(map);
	}
	
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        Map<String, Object> map = (Map<String, Object>)l.getItemAtPosition(position);

        Intent intent = (Intent) map.get("intent");
        startActivity(intent);
    }

}
